//
//  WeatherModel.swift
//  天气
//
//  Created by 邢胡斯盛 on 2024/10/10.
//

struct WeatherModel {
    // 天气类型所对应的id
    let conditionID: Int
    // 摄氏温度
    let temperature: Float
    // 城市名
    let cityName: String
    // 天气描述
    let weatherDescription: String
    
    // 根据天气类型所对应的id计算需要显示的天气类型图像
    var conditionImageName: String {
        switch conditionID {
        case 200...232:
            return "cloud.bolt"
        case 300...321:
            return "cloud.drizzle"
        case 500...531:
            return "cloud.rain"
        case 600...622:
            return "cloud.snow"
        case 701...781:
            return "cloud.fog"
        case 800:
            return "sun.max"
        case 801...804:
            return "cloud"
        default:
            return "xmark.icloud.fill"
        }
    }
    
    // 格式化获取到的摄氏温度
    var temperatureString: String {
        return String(format: "%.1f", temperature)
    }
}
